home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 298_01 / curses.h < prev    next >
C/C++ Source or Header  |  1988-07-23  |  16KB  |  456 lines

  1. /* PC Curses. (C) Copyright 1987 Jeffrey S. Dean.  All Rights Reserved. */
  2.  
  3. /* curses.h -- include file for PC Curses */
  4.  
  5. #ifndef PC_CURSES
  6.  
  7. /* PC_CURSES is used to identify this particular package;
  8.  *  also ensures that this file is processed only once.
  9.  */
  10. #define PC_CURSES
  11.  
  12. #include <stdio.h>
  13.  
  14. /* version information */
  15. extern char *_pc_curses;
  16.  
  17. /* characters in PC Curses are always of type CHTYPE
  18.  *  in the current implementation, the upper byte is
  19.  *  used to store attribute information.
  20.  */
  21. #define CHTYPE short
  22.  
  23. /* the basic window structure */
  24. typedef struct  _win {
  25.     CHTYPE **txt;            /* text, as an array of line ptrs */
  26.     short cury, curx;        /* current x and y coordinates */
  27.     short ox, oy;            /* x and y origin */
  28.     short lines, cols;        /* size of full screen */
  29.     short mfy, mfx, mly, mlx;    /* area to be refreshed */
  30.     CHTYPE attrs;            /* screen attributes */
  31.     short flags;            /* miscellaneous information */
  32.     short scrtop, scrbot;        /* scrolling region boundaries */
  33.     CHTYPE *base;            /* base address of character map */
  34. } WINDOW;
  35.  
  36. #define A_ATTRIBUTES    0xff00
  37. #define A_CHARTEXT    0x00ff
  38.  
  39. /* Support is provided for both monochrome and color displays,
  40.  *  by providing a set of attributes that can be used with
  41.  *  the "attr" functions.
  42.  *
  43.  *  The meaning of the attributes depends on the display used.
  44.  *  Note that the meanings may not translate well: for example,
  45.  *  "underline" on a color display appears as blue text on a 
  46.  *  black background.
  47.  */ 
  48.  
  49. /* Although an attrbiute of zero means "invisible" on a PC, this package
  50.  * has been hacked (for compatibility) so that zero also means "normal".
  51.  */
  52. #define    A_NONE        0
  53. #define A_NORMAL    0x0700
  54.  
  55. /* On a PC, if !(attributes & A_VISIBLE), character will be invisible */
  56. #define A_VISIBLE    0x7700
  57.  
  58. /* screen attributes for (monochrome) IBM PC
  59.  *   Note that not all combinations are meaningful;
  60.  *   see a PC reference manual for more info.
  61.  */
  62. #define A_REVERSE    0x7000 
  63. #define A_UNDERLINE    0x0100 
  64. #define A_BOLD        0x0800 
  65. #define A_BLINK        0x8000 
  66. #define A_STANDOUT    A_REVERSE 
  67. #define A_DIM        A_NONE
  68.  
  69. /* color attributes
  70.  *  use the A_COLOR macro to specify foreground and background colors.
  71.  *  For example, to set the stdscr to use green characters on a yellow
  72.  *  background, you would say:
  73.  *    attrset( A_COLOR(A_GREEN, A_YELLOW) );
  74.  */
  75. #define A_COLOR(fore,back)    ( (fore) << 8 | (back) <<12 )
  76.  
  77. /* primary colors */
  78. #define A_BLACK        0
  79. #define A_BLUE        1
  80. #define A_GREEN        2
  81. #define A_RED        4
  82.  
  83. /* secondary colors (combinations of primary colors) */
  84. #define A_CYAN        3    /* blue-green */
  85. #define A_MAGENTA    5    /* purple */
  86. #define A_BROWN        6    /* (or dark yellow) */
  87. #define A_WHITE        7    /* white (or light gray) */
  88.  
  89. /* the "intensity" bit
  90.  *  Warning: If used on the background color, the intensity bit
  91.  *  will cause the text to blink.  This reduces the number of
  92.  *  background colors from 16 to 8.  (There is a hardware-dependent
  93.  *  method around this problem, but PC Curses does not support it.)
  94.  */
  95. #define A_INTENSE    8
  96.  
  97. /* "light" colors */
  98. #define A_GRAY        (A_INTENSE|A_BLACK)
  99. #define A_LBLUE        (A_INTENSE|A_BLUE)
  100. #define A_LGREEN    (A_INTENSE|A_GREEN)
  101. #define A_LCYAN        (A_INTENSE|A_CYAN)
  102. #define A_LRED        (A_INTENSE|A_RED)
  103. #define A_LMAGENTA    (A_INTENSE|A_MAGENTA)
  104. #define A_YELLOW    (A_INTENSE|A_BROWN)
  105. #define A_BRIGHTWHITE    (A_INTENSE|A_WHITE)
  106.  
  107. /* Unix Sys V.3 extended character set
  108.  *
  109.  * Note: this is an approximation of the V.3 approach,
  110.  * which requires that all line graphics characters have the
  111.  * bit A_ALTCHARSET turned on (if it is off, it means that
  112.  * the terminal does not support that particular character).
  113.  * Since PC Curses provides color support (see above), there are
  114.  * no extra bits available for A_ALTCHARSET.  As an approximation,
  115.  * A_ALTCHARSET is defined as 0x80.  Since many of the PC graphics
  116.  * characters have this bit set, this approximation works most of
  117.  * the time.  However, some graphics characters fall in the range
  118.  * 0x00 to 0x1F, which means that testing for A_ALTCHARSET will
  119.  * fail.
  120.  */
  121. #define A_ALTCHARSET    0x0080
  122. #define ACS_ULCORNER    218
  123. #define ACS_LLCORNER    192
  124. #define ACS_URCORNER    191
  125. #define ACS_LRCORNER    217
  126. #define ACS_RTEE    180
  127. #define ACS_LTEE    195
  128. #define ACS_BTEE    193
  129. #define ACS_TTEE    194
  130. #define ACS_HLINE    196
  131. #define ACS_VLINE    179
  132. #define ACS_PLUS    '+'
  133. #define ACS_DIAMOND    4
  134. #define ACS_CKBOARD    176
  135. #define ACS_DEGREE    248
  136. #define ACS_PLMINUS    241
  137. #define ACS_BULLET    249
  138. #define ACS_LARROW    27
  139. #define ACS_RARROW    26
  140. #define ACS_DARROW    25
  141. #define ACS_UARROW    24
  142. #define ACS_BOARD    '#'
  143. #define ACS_LANTERN    '#'
  144.  
  145. /* "double line" characters (not defined by SysV.3) */
  146. #define ACS_DULCORNER    201
  147. #define ACS_DLLCORNER    100
  148. #define ACS_DURCORNER    187
  149. #define ACS_DLRCORNER    188
  150. #define ACS_DRTEE    185
  151. #define ACS_DLTEE    204
  152. #define ACS_DBTEE    202
  153. #define ACS_DTTEE    203
  154. #define ACS_DHLINE    205
  155. #define ACS_DVLINE    186
  156.  
  157. /* Curses provides getyx() to return current coordinates; newer versions
  158.  * of curses also provide getbegyx() and getmaxyx() to return beginning
  159.  * and ending coordinates.  The coordinate accessing macros below are
  160.  * non-standard, but they allow just a single coordinate to be accessed.
  161.  * This saves the trouble of declaring an unneeded variable, eliminates
  162.  * an unneeded assignment, and prevents the compiler (or lint) from
  163.  * complaining about a variable that is set but never used.
  164.  */
  165. #define BEGY(w)        w->oy        /* starting position of window */
  166. #define BEGX(w)        w->ox
  167. #define CURY(w)        w->cury        /* current position in window */
  168. #define CURX(w)        w->curx
  169. #define MAXY(w)     w->lines    /* number of lines */
  170. #define MAXX(w)        w->cols        /* number of columns */
  171. #define WGETC(w,y,x)    w->txt[y][x]    /* get character from window */
  172. #define WPUTC(w,y,x,c)    w->txt[y][x]=c    /* place character in window */
  173.  
  174. /* for win->flags */
  175. /* #define W_WRAPOK    0x1        /* ok for lines to wrap around */
  176. #define W_CLEAROK    0x2        /* ok to clear window */
  177. #define W_MODIFIED    0x4        /* window has been modified */
  178. #define W_SCROLLOK    0x8        /* ok to scroll window */
  179. #define W_KEYPAD    0x10        /* use keypad translations */
  180. #define W_NODELAY    0x20        /* non-blocking tty input */
  181. #define W_TOUCHED    0x40        /* window has been touched */
  182. #define W_SUBWIN    0x80        /* window is a sub-window */
  183. #define W_LEAVEOK    0x100        /* ignore cursor */
  184. #define W_META        0x200        /* enable meta mode */
  185. #define W_PAD        0x400        /* window is really a pad */
  186. #define W_PADNOCUR    0x800        /* internal pad cursor control */
  187. #define W_FULLWIN    0x1000        /* window is full screen */
  188.  
  189. /* macros to set/clear win->flags */
  190. #define scrollok(win,flag)    _winflag(win,flag,W_SCROLLOK)
  191. #define nodelay(win,flag)    _winflag(win,flag,W_NODELAY)
  192. #define leaveok(win,flag)    _winflag(win,flag,W_LEAVEOK)
  193. #ifndef SIMPGETCH
  194. #define keypad(win,flag)    _winflag(win,flag,W_KEYPAD)
  195. #define meta(win,flag)        _winflag(win,flag,W_META)
  196. #endif
  197. #define clearok(win,flag) \
  198.     ( (win)->flags & W_FULLWIN ? _winflag(win, flag, W_CLEAROK) : ERR )
  199.  
  200. /* standard stuff for curses */
  201. #define TRUE    1
  202. #define FALSE    0
  203. #define    ERR    0
  204. #define    OK    1
  205.  
  206. /* standard curses variables */
  207. extern int LINES, COLS;            /* size of full screen */
  208. extern WINDOW *stdscr, *curscr;        /* current and standard screens */
  209.  
  210. /* for tty input emulation mode */
  211. extern int _ttyflags;
  212.  
  213. #define T_RAW    01
  214. #define T_CRMOD    02
  215. #define T_ECHO    04
  216. #define T_NONL    010
  217.  
  218. /* settings for screen update method; this is still experimental */
  219. #define T_BIOS        0        /* use bios updating */
  220. #define T_DIRECT    -1        /* direct update, figure out type */
  221. #define T_MA        0xb000        /* direct update, assume monochrome */
  222. #define T_CGA        0xb800        /* direct update, assume cga */
  223. #define T_EGA        0xa800        /* direct update, assume ega ?? */
  224.  
  225. /* PC line drawing characters (horizontal/vertical pairs) */
  226. #define S_HOR    196    /* single line */
  227. #define S_VERT    179
  228. #define D_HOR    205    /* double line */
  229. #define D_VERT    186
  230. #define T_HOR    220    /* thick solid line, not quite perfect */
  231. #define T_VERT    219
  232.  
  233. WINDOW    *initscr(), *newwin(), *subwin(), *newpad();
  234. WINDOW    *shadowwin();
  235. char    *unctrl();
  236.  
  237. #define    getyx(win,y,x)        (y = CURY(win), x = CURX(win))
  238. #define getbegy